package com.example.demo0

import com.example.util.p

data class Book(val name:String)

class Bookcase(private val books:List<Book>):Iterator<Book>{

    private val iterator:Iterator<Book> = books.iterator()

    override fun hasNext() = this.iterator.hasNext()

    override fun next() = this.iterator.next()

}



fun main(){
    val bookcase = Bookcase(listOf(Book("Dive into kotlin"),Book("Thinking in java")))

    while (bookcase.hasNext()){
        p("The book name is ${bookcase.next().name}")
    }

    //no output again
    for(book in bookcase){
        p(book.name)
    }

}






